#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3005;
const int INF = 1e9;

int n, m;
int c[N], r[N], sz[N];
vector<int> ch[N];
int dp[N][N];
void dfs(int u) {
  rep(i, 1, m) dp[u][i] = -INF;
  if (ch[u].empty()) {
    dp[u][1] = r[u] - c[u];
    sz[u] = 1;
    return;
  }
  for (int v : ch[u]) {
    dfs(v);
    sz[u] += sz[v];
    per(i, sz[u], 1) {
      rep(j, 1, sz[v]) dp[u][i] = max(dp[u][i], dp[u][i - j] + dp[v][j]);
    }
  }
  rep(i, 1, sz[u]) dp[u][i] -= c[u];
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n - m) {
    int k;
    cin >> k;
    rep(j, 1, k) {
      int id;
      cin >> id;
      cin >> c[id];
      ch[i].push_back(id);
    }
  }
  rep(i, n - m + 1, n) cin >> r[i];
  dfs(1);
  int ans = 0;
  per(i, m, 1) if (dp[1][i] >= 0) {
    ans = i;
    break;
  }
  cout << ans;
  return 0;
}